package cn.jbolt.ai.resource.vdb.entity;

import cn.hutool.core.util.StrUtil;
import com.jboltai.resource.embedding.EmbeddingModelType;
import cn.jbolt.ai.resource.vdb.VDBType;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;

import java.io.Serializable;
import java.util.Date;

/**
 * VDB资源表
 */
@TableName("ja_vdb_resource")
public class VDBResource implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.ASSIGN_ID)
    @Schema(name = "id", description = "主键ID")
    private Long id;

    @Schema(name = "type", description = "类型")
    @TableField("type")
    private String type;

    @Schema(name = "name", description = "名称")
    @TableField("name")
    private String name;

    @Schema(name = "enable", description = "是否启用")
    @TableField("enable")
    private Boolean enable;

    @Schema(name = "embedding", description = "embedding资源")
    @TableField("embedding")
    private String embedding;



    @Schema(name = "url", description = "地址")
    @TableField("url")
    private String url;

    @Schema(name = "username", description = "用户名")
    @TableField("username")
    private String username;

    @Schema(name = "password", description = "密码")
    @TableField("password")
    private String password;

    @Schema(name = "databaseName", description = "数据库名称")
    @TableField(value = "database_name")
    private String databaseName;

    @Schema(name = "timeout", description = "超时时间")
    @TableField("timeout")
    private Integer timeout;

    @Schema(name = "createTime", description = "创建时间")
    @JsonFormat(locale = "zh", pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    //以下是非数据库字段
    @TableField(exist = false)
    private String modelName;


    public String getEmbeddingName() {
        if (embedding == null) return null;
        String[] args = embedding.split(":", 2);
        return EmbeddingModelType.getBySn(args[0]).getName() + ((args.length > 1 && StrUtil.isNotBlank(args[1])) ? (":" + args[1]) : "");
    }


    // Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }



    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDatabaseName() {
        return databaseName;
    }

    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }

    public Integer getTimeout() {
        return timeout;
    }

    public void setTimeout(Integer timeout) {
        this.timeout = timeout;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getEmbedding() {
        return embedding;
    }

    public void setEmbedding(String embedding) {
        this.embedding = embedding;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getModelName() {
        return VDBType.getBySn(type).getName();
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

}
